package com.zking.web.ypf;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.alibaba.fastjson.JSONObject;
import com.zking.dao.domain.MyResume;
import com.zking.dao.domain.User;
import com.zking.service.ypf.MyResumeService;
import com.zking.utils.RedisUtil;

@Controller
@RequestMapping(value ="/MyResume" )
public class MyResumeController {

	@Autowired
	MyResumeService myResumeService;

	@Autowired
	private RedisUtil redisUtil;

	//	@RequestMapping(value = "/insert")
	//		public String insert(MyResume myResume,HttpServletRequest request) {
	//		int i=myResumeService.insert(myResume);
	//		System.out.println("已进来");
	//		if(i!=0) {
	//			System.out.println(myResume);
	//			return "jianli";
	//		}else {
	//			return "jianli";
	//		}
	//		}
	//	
	//	@RequestMapping(value = "/update")
	//		public String update(MyResume myResume,HttpServletRequest request) {
	//		//myResumeService.select(myResume.getMyResumeId());
	//			request.getSession().getAttribute(name);
	//			request.getSession().setAttribute(name, value);
	//		System.out.println("已进来update");
	//		System.out.println(myResume);
	//		int i=myResumeService.updateOne(myResume);
	//		System.out.println(i);
	//		if(i==1) {
	//			System.out.println(myResume);
	//			return "jianli";
	//		}else {
	//			return "jianli";
	//		}
	//		}
	@RequestMapping(value = "/MyResumeRides01")
	@ResponseBody
	public String MyResumeRides01(MyResume myResume) {
		redisUtil.set("myResume", JSONObject.toJSONString(myResume));
		return redisUtil.get("myResume").toString();
	}

	@RequestMapping(value = "/MyResumeRides02")
	@ResponseBody
	public String MyResumeRides02(MyResume myResume) {
		//将原来存储的User的json数据取出来，再往里面存储一些数据
		MyResume RedismyResume=JSONObject.parseObject(redisUtil.get("myResume").toString(),MyResume.class);
		RedismyResume.setCity(myResume.getCity());
		RedismyResume.setWork_type(myResume.getWork_type());
		RedismyResume.setPosition(myResume.getPosition());
		RedismyResume.setSalary(myResume.getSalary());
		//将原来的myResume覆盖
		redisUtil.set("myResume",JSONObject.toJSONString(RedismyResume));
		return redisUtil.get("myResume").toString();
	}

	@RequestMapping(value = "/MyResumeRides03")
	@ResponseBody
	public String MyResumeRides03(MyResume myResume) {
		//将原来存储的User的json数据取出来，再往里面存储一些数据
		MyResume RedismyResume=JSONObject.parseObject(redisUtil.get("myResume").toString(),MyResume.class);
		//System.out.println(RedismyResume);
//		private String company_name;//公司名称
//		private String company_position;//公司职位
//		private String company_time;//公司的开始年份
//		private String com_month;//工作开始月份
//		private String com_endyear;//工作结束年份
//		private String com_endmonth;//工作结束月份
		RedismyResume.setCompany_name(myResume.getCompany_name());
		RedismyResume.setCompany_position(myResume.getCompany_position());
		RedismyResume.setCompany_time(myResume.getCompany_time());
		RedismyResume.setCom_month(myResume.getCom_month());
		RedismyResume.setCom_endyear(myResume.getCom_endyear());
		RedismyResume.setCom_endmonth(myResume.getCom_endmonth());
		//将原来的myResume覆盖
		redisUtil.set("myResume",JSONObject.toJSONString(RedismyResume));
		System.out.println(RedismyResume);
		return redisUtil.get("myResume").toString();
	}

	@RequestMapping(value = "/MyResumeRides04")
	@ResponseBody
	public String MyResumeRides04(MyResume myResume) {
		//将原来存储的User的json数据取出来，再往里面存储一些数据
		MyResume RedismyResume=JSONObject.parseObject(redisUtil.get("myResume").toString(),MyResume.class);
//		private String pj_name;//项目名称
//		private String pj_position;//项目职位
//		private String pj_time_year;//开始年份
//		private String pj_time_month;//开始月份
//		private String pj_end_year;//结束年份
//		private String pj_end_month;//结束月份
//		private String pj_description;//项目描述
		RedismyResume.setPj_name(myResume.getPj_name());
		RedismyResume.setPj_position(myResume.getPj_position());
		RedismyResume.setPj_time_year(myResume.getPj_time_year());
		RedismyResume.setPj_time_month(myResume.getPj_time_month());
		RedismyResume.setPj_end_year(myResume.getPj_end_year());
		RedismyResume.setPj_end_month(myResume.getPj_end_month());
		RedismyResume.setPj_description(myResume.getPj_description());
		//将原来的myResume覆盖
		redisUtil.set("myResume",JSONObject.toJSONString(RedismyResume));
		System.out.println(RedismyResume);
		return redisUtil.get("myResume").toString();
	}
	@RequestMapping(value = "/MyResumeRides05")
	@ResponseBody
	public String MyResumeRides05(MyResume myResume) {
		MyResume RedismyResume=JSONObject.parseObject(redisUtil.get("myResume").toString(),MyResume.class);
		RedismyResume.setSchool_name(myResume.getSchool_name());
		RedismyResume.setEducation_type(myResume.getEducation_type());
		RedismyResume.setProfessional(myResume.getProfessional());
		RedismyResume.setSchool_time_start(myResume.getSchool_time_start());
		RedismyResume.setSchool_time_end(myResume.getSchool_time_end());
		//将原来的myResume覆盖
		redisUtil.set("myResume", JSONObject.toJSONString(RedismyResume));
		System.out.println(RedismyResume);
		return redisUtil.get("myResume").toString();
	}
	@RequestMapping(value = "/MyResumeRides06")
	public String MyResumeRides06(MyResume myResume,HttpSession session,User user) {
		MyResume RedismyResume=JSONObject.parseObject(redisUtil.get("myResume").toString(),MyResume.class);
		RedismyResume.setIntroduction(myResume.getIntroduction());
		//request.getSession().getAttribute("user.getId()");
		Object object=session.getAttribute("user");
		user = (User) object;
		user.getId();
		RedismyResume.setUser_id(user.getId());
		//将原来的myResume覆盖
		redisUtil.set("myResume", JSONObject.toJSONString(RedismyResume));
		//redisUtil.set("myResume", JSONObject.toJSONString(RedismyResume));
		System.out.println(RedismyResume);
		return "redirect:/MyResume/ClearMyResumeRides";
	}
	
	@RequestMapping(value = "/ClearMyResumeRides")
	public String MyResumeRides07(MyResume myResume) {
		System.out.println("进来了");
		MyResume RedismyResume=JSONObject.parseObject(redisUtil.get("myResume").toString(),MyResume.class);
		//int i=myResumeService.insert(RedismyResume);
		int i=myResumeService.updateOne(RedismyResume);
		redisUtil.del("myResume");
		if(i!=0) {
			return "jianli";
		}else {
			return "jianli";
		}
	}
}
